package com.ymatou.iapi.tradingsettlement.testcase;

import java.math.BigDecimal;
import java.util.List;

import org.json.JSONException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.optrade.parameter.enums.CancelOrderTypeEnum;
import com.ymatou.iapi.optrade.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.optrade.resp.Order;
import com.ymatou.iapi.optrade.resp.TradingServiceResp;
import com.ymatou.iapi.synctrade.service.TradingSyncService;
import com.ymatou.iapi.tradingsettlement.parameter.OrderCommissionReq;
import com.ymatou.iapi.tradingsettlement.service.OrderCommissionCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.HunterCallService;
import com.ymttest.business.service.PayGateWayCallService;
import com.ymttest.business.service.YMTTrading.TradingCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceHunterOrderCallService;
import com.ymttest.database.model.hunter.HunterSettlement;
import com.ymttest.database.sharding.db.sharding.model.OrderPo;
import com.ymttest.database.sharding.db.sqlwapper.OrderShardingWapper;
import com.ymttest.database.sqlwapper.hunter.HunterSettlementWrapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;

@Ignore
public class Ts_OrderCommission {

	private static OrderCommissionReq orderCommissionReq;
	private static OrderCommissionCall orderCommissionCall;

	private static long userId = Long.valueOf(EnvSetup.getData("BuyUserId"));
	HunterSettlementWrapper hunterSettlementWrapper = new HunterSettlementWrapper();

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询某推手某订单销售佣金");
	}

	@Before
	public void caseUp() {
		orderCommissionReq = new OrderCommissionReq();
		orderCommissionCall = new OrderCommissionCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(orderCommissionCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	public void verifyDb() throws JSONException {

		HunterSettlement actualHunterSettlement = hunterSettlementWrapper
				.selectHunterSettlementByOrderIdAndHunterId(
						orderCommissionReq.getHunterId(),
						orderCommissionReq.getOrderId());
		String actualAmount = "";

		if (null == actualHunterSettlement
				|| actualHunterSettlement.getSettlement_status() == 2
				|| actualHunterSettlement.getSettlement_type() == 21
				|| actualHunterSettlement.getSettlement_type() == 23
				|| actualHunterSettlement.getSettlement_type() == 30)
			actualAmount = null;
		else
			actualAmount = actualHunterSettlement.getTotal_amount()
					.stripTrailingZeros().toPlainString();
		
		String expectAmount = "";
		
		if ("".equalsIgnoreCase(orderCommissionCall.getData().optString("amount")))
			expectAmount = null;
		else
			expectAmount = new BigDecimal(orderCommissionCall.getData()
					.optString("amount")).stripTrailingZeros().toPlainString();

		DataUtil.verifyEquals(expectAmount, actualAmount, "验证amount");
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderCommission_001() {
		Logger.start(true, "查询推手未结算的普通商品销售佣金");
		try {

			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			long hunterId = 1022;

			// 未结算的普通商品数据
			TradingServiceResp notSettledGiftPackagePlaceOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, 2);

			PayGateWayCallService.notifyCall(
					"13",
					TradingCallService.payOrder(userId, BigDecimal.ZERO,
							notSettledGiftPackagePlaceOrder.getTradingId(),
							"13").toString(), notSettledGiftPackagePlaceOrder
							.getPayableAmount().subtract(BigDecimal.ZERO)
							.toString(), (int) userId);
			TradingSyncService.getSyncResult(notSettledGiftPackagePlaceOrder
					.getOrderList().get(0).getOrderId());

			Logger.comment("前置数据结束");

			orderCommissionReq.setHunterId(1023);
			orderCommissionReq.setOrderId(notSettledGiftPackagePlaceOrder
					.getOrderList().get(0).getOrderId());

			orderCommissionCall.setData(orderCommissionReq);
			orderCommissionCall.callService();

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderCommission_002() {
		Logger.start(true, "查询推手结算的普通商品销售佣金");
		try {

			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			long hunterId = 1022;

			// 未结算的大礼包数据
			TradingServiceResp notSettledGiftPackagePlaceOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, 2);
			long notSettledGiftPackagePlaceOrderSellerId = notSettledGiftPackagePlaceOrder
					.getOrderList().get(0).getSellerId();
			long notSettledGiftPackagePlaceOrderOrderId = notSettledGiftPackagePlaceOrder
					.getOrderList().get(0).getOrderId();

			PayGateWayCallService.notifyCall(
					"13",
					TradingCallService.payOrder(userId, BigDecimal.ZERO,
							notSettledGiftPackagePlaceOrder.getTradingId(),
							"13").toString(), notSettledGiftPackagePlaceOrder
							.getPayableAmount().subtract(BigDecimal.ZERO)
							.toString(), (int) userId);
			TradingSyncService.getSyncResult(notSettledGiftPackagePlaceOrder
					.getOrderList().get(0).getOrderId());

			// 拼邮国际段发货
			TradingCallService.delivery(
					notSettledGiftPackagePlaceOrderSellerId,
					notSettledGiftPackagePlaceOrderOrderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService
					.getSyncResult(notSettledGiftPackagePlaceOrderOrderId);
			// 拼邮国内段发货
			TradingCallService.delivery(
					notSettledGiftPackagePlaceOrderSellerId,
					notSettledGiftPackagePlaceOrderOrderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			// 推手结算
			hunterSettlementWrapper.updateExpectSettlementTimeByOrderId(
					YMTDateUtil.getBeforeOrNextDate(-1),
					notSettledGiftPackagePlaceOrderOrderId);
			HunterCallService.doCommissionSettlement();

			Logger.comment("前置数据结束");

			orderCommissionReq.setHunterId(hunterId);
			orderCommissionReq
					.setOrderId(notSettledGiftPackagePlaceOrderOrderId);

			orderCommissionCall.setData(orderCommissionReq);
			orderCommissionCall.callService();

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderCommission_003() {
		Logger.start(true, "查询推手未结算的大礼包销售佣金");
		try {

			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			long hunterId = 1022;

			// 未结算的大礼包数据
			TradingServiceResp notSettledGiftPackagePlaceOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, 1);

			PayGateWayCallService.notifyCall(
					"13",
					TradingCallService.payOrder(userId, BigDecimal.ZERO,
							notSettledGiftPackagePlaceOrder.getTradingId(),
							"13").toString(), notSettledGiftPackagePlaceOrder
							.getPayableAmount().subtract(BigDecimal.ZERO)
							.toString(), (int) userId);
			TradingSyncService.getSyncResult(notSettledGiftPackagePlaceOrder
					.getOrderList().get(0).getOrderId());

			Logger.comment("前置数据结束");

			orderCommissionReq.setHunterId(hunterId);
			orderCommissionReq.setOrderId(notSettledGiftPackagePlaceOrder
					.getOrderList().get(0).getOrderId());

			orderCommissionCall.setData(orderCommissionReq);
			orderCommissionCall.callService();

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderCommission_004() {
		Logger.start(true, "查询推手结算的大礼包销售佣金");
		try {

			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			long hunterId = 1022;

			// 未结算的大礼包数据
			TradingServiceResp notSettledGiftPackagePlaceOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, 1);
			long notSettledGiftPackagePlaceOrderSellerId = notSettledGiftPackagePlaceOrder
					.getOrderList().get(0).getSellerId();
			long notSettledGiftPackagePlaceOrderOrderId = notSettledGiftPackagePlaceOrder
					.getOrderList().get(0).getOrderId();

			PayGateWayCallService.notifyCall(
					"13",
					TradingCallService.payOrder(userId, BigDecimal.ZERO,
							notSettledGiftPackagePlaceOrder.getTradingId(),
							"13").toString(), notSettledGiftPackagePlaceOrder
							.getPayableAmount().subtract(BigDecimal.ZERO)
							.toString(), (int) userId);
			TradingSyncService.getSyncResult(notSettledGiftPackagePlaceOrder
					.getOrderList().get(0).getOrderId());

			// 拼邮国际段发货
			TradingCallService.delivery(
					notSettledGiftPackagePlaceOrderSellerId,
					notSettledGiftPackagePlaceOrderOrderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService
					.getSyncResult(notSettledGiftPackagePlaceOrderOrderId);
			// 拼邮国内段发货
			TradingCallService.delivery(
					notSettledGiftPackagePlaceOrderSellerId,
					notSettledGiftPackagePlaceOrderOrderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			// 推手结算
			hunterSettlementWrapper.updateExpectSettlementTimeByOrderId(
					YMTDateUtil.getBeforeOrNextDate(-1),
					notSettledGiftPackagePlaceOrderOrderId);
			HunterCallService.doCommissionSettlement();

			Logger.comment("前置数据结束");

			orderCommissionReq.setHunterId(hunterId);
			orderCommissionReq
					.setOrderId(notSettledGiftPackagePlaceOrderOrderId);

			orderCommissionCall.setData(orderCommissionReq);
			orderCommissionCall.callService();

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderCommission_005() {
		Logger.start(true, "查询推手未结算的普通商品管理费，查询数据为空");
		try {

			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}
			
			long goldServiceId = HunterCallService.buildHunterRelation(3, 3, 0).get(0);
			long serviceId = HunterCallService.buildHunterRelation(2, 3, goldServiceId).get(0);
			long hunterId = HunterCallService.buildHunterRelation(1, 3, serviceId).get(0);

			// 未结算的大礼包数据
			TradingServiceResp notSettledGiftPackagePlaceOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, 2);

			PayGateWayCallService.notifyCall(
					"13",
					TradingCallService.payOrder(userId, BigDecimal.ZERO,
							notSettledGiftPackagePlaceOrder.getTradingId(),
							"13").toString(), notSettledGiftPackagePlaceOrder
							.getPayableAmount().subtract(BigDecimal.ZERO)
							.toString(), (int) userId);
			TradingSyncService.getSyncResult(notSettledGiftPackagePlaceOrder
					.getOrderList().get(0).getOrderId());

			Logger.comment("前置数据结束");

			orderCommissionReq.setHunterId(goldServiceId);
			orderCommissionReq.setOrderId(notSettledGiftPackagePlaceOrder
					.getOrderList().get(0).getOrderId());

			orderCommissionCall.setData(orderCommissionReq);
			orderCommissionCall.callService();

			DataUtil.verifyEquals(200, orderCommissionCall.getJSONData()
					.getInt("code"), "验证code");
			DataUtil.verifyEquals("", orderCommissionCall.getData()
					.optString("amount"), "验证amount");
			

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderCommission_006() {
		Logger.start(true, "查询推手结算的普通商品管理费,查询数据为空");
		try {

			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			long goldServiceId = HunterCallService.buildHunterRelation(3, 3, 0).get(0);
			long serviceId = HunterCallService.buildHunterRelation(2, 3, goldServiceId).get(0);
			long hunterId = HunterCallService.buildHunterRelation(1, 3, serviceId).get(0);

			// 未结算的大礼包数据
			TradingServiceResp notSettledGiftPackagePlaceOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, 2);
			long notSettledGiftPackagePlaceOrderSellerId = notSettledGiftPackagePlaceOrder
					.getOrderList().get(0).getSellerId();
			long notSettledGiftPackagePlaceOrderOrderId = notSettledGiftPackagePlaceOrder
					.getOrderList().get(0).getOrderId();

			PayGateWayCallService.notifyCall(
					"13",
					TradingCallService.payOrder(userId, BigDecimal.ZERO,
							notSettledGiftPackagePlaceOrder.getTradingId(),
							"13").toString(), notSettledGiftPackagePlaceOrder
							.getPayableAmount().subtract(BigDecimal.ZERO)
							.toString(), (int) userId);
			TradingSyncService.getSyncResult(notSettledGiftPackagePlaceOrder
					.getOrderList().get(0).getOrderId());

			// 拼邮国际段发货
			TradingCallService.delivery(
					notSettledGiftPackagePlaceOrderSellerId,
					notSettledGiftPackagePlaceOrderOrderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService
					.getSyncResult(notSettledGiftPackagePlaceOrderOrderId);
			// 拼邮国内段发货
			TradingCallService.delivery(
					notSettledGiftPackagePlaceOrderSellerId,
					notSettledGiftPackagePlaceOrderOrderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			// 推手结算
			hunterSettlementWrapper.updateExpectSettlementTimeByOrderId(
					YMTDateUtil.getBeforeOrNextDate(-1),
					notSettledGiftPackagePlaceOrderOrderId);
			HunterCallService.doCommissionSettlement();

			Logger.comment("前置数据结束");

			orderCommissionReq.setHunterId(goldServiceId);
			orderCommissionReq
					.setOrderId(notSettledGiftPackagePlaceOrderOrderId);

			orderCommissionCall.setData(orderCommissionReq);
			orderCommissionCall.callService();

			DataUtil.verifyEquals(200, orderCommissionCall.getJSONData()
					.getInt("code"), "验证code");
			DataUtil.verifyEquals("", orderCommissionCall.getData()
					.optString("amount"), "验证amount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderCommission_007() {
		Logger.start(true, "查询推手未结算的大礼包销售佣金");
		try {

			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			long goldServiceId = HunterCallService.buildHunterRelation(3, 3, 0).get(0);
			long serviceId = HunterCallService.buildHunterRelation(2, 3, goldServiceId).get(0);
			long hunterId = HunterCallService.buildHunterRelation(1, 3, serviceId).get(0);

			// 未结算的大礼包数据
			TradingServiceResp notSettledGiftPackagePlaceOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, 1);

			PayGateWayCallService.notifyCall(
					"13",
					TradingCallService.payOrder(userId, BigDecimal.ZERO,
							notSettledGiftPackagePlaceOrder.getTradingId(),
							"13").toString(), notSettledGiftPackagePlaceOrder
							.getPayableAmount().subtract(BigDecimal.ZERO)
							.toString(), (int) userId);
			TradingSyncService.getSyncResult(notSettledGiftPackagePlaceOrder
					.getOrderList().get(0).getOrderId());

			Logger.comment("前置数据结束");

			orderCommissionReq.setHunterId(goldServiceId);
			orderCommissionReq.setOrderId(notSettledGiftPackagePlaceOrder
					.getOrderList().get(0).getOrderId());

			orderCommissionCall.setData(orderCommissionReq);
			orderCommissionCall.callService();

			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderCommission_008() {
		Logger.start(true, "查询推手结算的大礼包管理费,查询数据为空");
		try {

			Logger.comment("前置数据准备");

			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);

			if (orderList.size() > 0) {
				for (OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER, userId);
				}
			}

			long goldServiceId = HunterCallService.buildHunterRelation(3, 3, 0).get(0);
			long serviceId = HunterCallService.buildHunterRelation(2, 3, goldServiceId).get(0);
			long hunterId = HunterCallService.buildHunterRelation(1, 3, serviceId).get(0);

			// 未结算的大礼包数据
			TradingServiceResp notSettledGiftPackagePlaceOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, userId, 1);
			long notSettledGiftPackagePlaceOrderSellerId = notSettledGiftPackagePlaceOrder
					.getOrderList().get(0).getSellerId();
			long notSettledGiftPackagePlaceOrderOrderId = notSettledGiftPackagePlaceOrder
					.getOrderList().get(0).getOrderId();

			PayGateWayCallService.notifyCall(
					"13",
					TradingCallService.payOrder(userId, BigDecimal.ZERO,
							notSettledGiftPackagePlaceOrder.getTradingId(),
							"13").toString(), notSettledGiftPackagePlaceOrder
							.getPayableAmount().subtract(BigDecimal.ZERO)
							.toString(), (int) userId);
			TradingSyncService.getSyncResult(notSettledGiftPackagePlaceOrder
					.getOrderList().get(0).getOrderId());

			// 拼邮国际段发货
			TradingCallService.delivery(
					notSettledGiftPackagePlaceOrderSellerId,
					notSettledGiftPackagePlaceOrderOrderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 1);
			TradingSyncService
					.getSyncResult(notSettledGiftPackagePlaceOrderOrderId);
			// 拼邮国内段发货
			TradingCallService.delivery(
					notSettledGiftPackagePlaceOrderSellerId,
					notSettledGiftPackagePlaceOrderOrderId,
					LogisticsTypeEnum.OVERSEAS_DELIVERY, 3);

			// 推手结算
			hunterSettlementWrapper.updateExpectSettlementTimeByOrderId(
					YMTDateUtil.getBeforeOrNextDate(-1),
					notSettledGiftPackagePlaceOrderOrderId);
			HunterCallService.doCommissionSettlement();

			Logger.comment("前置数据结束");

			orderCommissionReq.setHunterId(goldServiceId);
			orderCommissionReq
					.setOrderId(notSettledGiftPackagePlaceOrderOrderId);

			orderCommissionCall.setData(orderCommissionReq);
			orderCommissionCall.callService();

			DataUtil.verifyEquals(200, orderCommissionCall.getJSONData()
					.getInt("code"), "验证code");
			DataUtil.verifyEquals("", orderCommissionCall.getData()
					.optString("amount"), "验证amount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderCommission_009() {
		Logger.start(true, "查询推手废弃的订单，查询数据为空");
		try {

			Logger.comment("前置数据准备");
			
			OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
			List<OrderPo> orderList = orderShardingWapper
					.selectHunterGiftBagOrderbyUserId(userId);
			
			if (orderList.size() > 0) {
				for(OrderPo po : orderList) {
					TradingCallService.cancelOrder(po.getOrderId(),
							CancelOrderTypeEnum.BUYER_CANCEL_ORDER,
							userId);
				}
			}
			
			long hunterId = 1022;
			int hunterOrderType = 2;
			TradingServiceResp placeOrder = TradingPlaceHunterOrderCallService
					.placeHunterOrder(hunterId, hunterOrderType);
			Long userId = placeOrder.getUserId();
			Order order = placeOrder.getOrderList().get(0);
			long orderId = order.getOrderId();
			long tradingId = placeOrder.getTradingId();
			BigDecimal totalPrice = placeOrder.getPayableAmount();
			
			Long thirdTradingId = TradingCallService.payOrder(userId,
					BigDecimal.ZERO, tradingId, "13");
			
			PayGateWayCallService.notifyCall("13",
					thirdTradingId.toString(),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue());
			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(5000);
			
			HunterCallService.hunterOrderRefund(order, true, 0);
			
			Thread.sleep(4000);

			// 支付网关退款回调
			PayGateWayCallService.refundNotifyCall("13",
					thirdTradingId.toString(), userId.intValue());
			
			Thread.sleep(3000);
			
			Logger.comment("前置数据准备结束");

			orderCommissionReq.setHunterId(hunterId);
			orderCommissionReq
					.setOrderId(orderId);

			orderCommissionCall.setData(orderCommissionReq);
			orderCommissionCall.callService();

			DataUtil.verifyEquals(200, orderCommissionCall.getJSONData()
					.getInt("code"), "验证code");
			DataUtil.verifyEquals("", orderCommissionCall.getData()
					.optString("amount"), "验证amount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderCommission_010() {
		Logger.start(true, "推手id与orderid不匹配");
		try {

			orderCommissionReq.setHunterId(1022);
			orderCommissionReq.setOrderId(2283038699L);

			orderCommissionCall.setData(orderCommissionReq);
			orderCommissionCall.callService();

			DataUtil.verifyEquals(200, orderCommissionCall.getJSONData()
					.getInt("code"), "验证code");
			DataUtil.verifyEquals("", orderCommissionCall
					.getData().optString("amount"), "验证amount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderCommission_011() {
		Logger.start(true, "推手id为0");
		try {

			orderCommissionReq.setHunterId(0);
			orderCommissionReq.setOrderId(2283038699L);

			orderCommissionCall.setData(orderCommissionReq);
			orderCommissionCall.callService();

			DataUtil.verifyEquals(400, orderCommissionCall.getJSONData()
					.getInt("code"), "验证code");
			DataUtil.verifyEquals(100, orderCommissionCall.getJSONData()
					.getInt("bcode"), "验证bcode");
			DataUtil.verifyEquals("hunterId:推手id不能为空", orderCommissionCall
					.getJSONData().getString("msg"), "验证msg");
			DataUtil.verifyEquals(false, orderCommissionCall.getData()
					.getBoolean("success"), "验证success");
			DataUtil.verifyEquals("ILLEGAL_ARGUMENT", orderCommissionCall
					.getData().getString("errorCode"), "验证errorCode");
			DataUtil.verifyEquals("hunterId:推手id不能为空", orderCommissionCall
					.getData().getString("errorMessage"), "验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderCommission_012() {
		Logger.start(true, "orderid为0");
		try {

			orderCommissionReq.setHunterId(1022);
			orderCommissionReq.setOrderId(0);

			orderCommissionCall.setData(orderCommissionReq);
			orderCommissionCall.callService();

			DataUtil.verifyEquals(400, orderCommissionCall.getJSONData()
					.getInt("code"), "验证code");
			DataUtil.verifyEquals(100, orderCommissionCall.getJSONData()
					.getInt("bcode"), "验证bcode");
			DataUtil.verifyEquals("orderId:订单号不能为0", orderCommissionCall
					.getJSONData().getString("msg"), "验证msg");
			DataUtil.verifyEquals(false, orderCommissionCall.getData()
					.getBoolean("success"), "验证success");
			DataUtil.verifyEquals("ILLEGAL_ARGUMENT", orderCommissionCall
					.getData().getString("errorCode"), "验证errorCode");
			DataUtil.verifyEquals("orderId:订单号不能为0", orderCommissionCall
					.getData().getString("errorMessage"), "验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
